package com.unlp.javaclickers.docente.vistas;

import javax.swing.JFrame;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JProgressBar;

public class PreguntaEnCurso {

	private JFrame frame;
	private JFrame Main;
	private Integer idClase;
	private int cantidad;
	private Timer timer;
	private Font fuente = new Font("Teen", Font.BOLD, 16);
	private JLabel lblNewLabel_2;
	private JProgressBar progressBar;
	private int contador;
	private JPanel panel_6;
	public PreguntaEnCurso() {
		initialize();
	}

	private void initialize() {
		frame = new JFrame();
		frame.getContentPane().setBackground(Color.WHITE);
		frame.setBounds(100, 100, 544, 525);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(
				new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
		frame.setFont(fuente);

		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		frame.getContentPane().add(panel);
		panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(getClass().getResource("logo.PNG")));
		panel.add(lblNewLabel);

		JPanel panel_2 = new JPanel();
		panel_2.setBackground(Color.WHITE);
		frame.getContentPane().add(panel_2);

		lblNewLabel_2 = new JLabel();
		lblNewLabel_2.setFont(new Font("Teen", Font.BOLD, 22));
		panel_2.add(lblNewLabel_2);

		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.WHITE);
		frame.getContentPane().add(panel_1);
		panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		panel_6 = new JPanel();
		panel_6.setBackground(Color.WHITE);
		frame.getContentPane().add(panel_6);
		progressBar = new JProgressBar();
		panel_6.add(progressBar);

	}

	public void cambiarNombreTiempoProblema(String s, int t) {
		timer = new Timer();
		lblNewLabel_2.setText("Contestando Problema: " + s);
		panel_6.remove(progressBar);
		progressBar = new JProgressBar(0, t);
		progressBar.setStringPainted(true);
		contador = 0;
		panel_6.add(progressBar);
		SwingUtilities.updateComponentTreeUI(frame);
		// for(int i=0; i<= t; i++){
		timer.scheduleAtFixedRate(new mainTask(), 0, 1000);
		// }

	}

	public void cancelarTimer() {
		timer.cancel();
	}

	private class mainTask extends TimerTask {

		@Override
		public void run() {
			progressBar.setValue(contador);
			contador++;
		}

	}

	public JFrame getFrame() {
		return frame;
	}

	public void setFrame(JFrame frame) {
		this.frame = frame;
	}

	public JFrame getMain() {
		return Main;
	}

	public void setMain(JFrame main) {
		Main = main;
	}

	public Integer getIdClase() {
		return idClase;
	}

	public void setIdClase(Integer idClase) {
		this.idClase = idClase;
	}

	public int getCantidad() {
		return cantidad;
	}

	public void setCantidad(int cantidad) {
		this.cantidad = cantidad;
	}

}
